<template>
    <div>
        <h1>权益展示</h1>
        <a href="/User">返回</a>
        <br>
        <input type="button" value="前往添加权益" @click="GetAdd">
        <table class="table">
            <thead>
                <tr>
                    <th>权益编号</th>
                    <th>权益名称</th>
                    <th>状态</th>
                    <th>描述</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                <tr v-for="d in data">
                    <td>{{d.Qid}}</td>
                    <td>{{d.Qyname}}</td>
                    <td>{{d.State?"启用":"禁用"}}</td>
                    <td>{{ d.Qysm }}</td>
                    <td>
                        <input type="button" :value="d.State?'禁用':'启用'" @click="UptState(d.Qid)">
                        <input type="button" value="删除" @click="Dels(d.Qid)">
                        <input type="button" value="修改" @click="GetUpt(d.Qid)">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import {ref,onMounted} from 'vue';
import axios from 'axios';
import { useRouter } from 'vue-router';


var touer=useRouter();

const data=ref([{
    "Qid": 0,
  "Qyname": "",
  "State": true,
  "Qysm": ""
}])

//钩子
onMounted(() => {
    Shows();
})



//显示
const Shows=()=>{
    axios.get("https://localhost:7185/api/QY/GetAllQy").then(res=>{
        data.value=res.data;
    })
}


//修改状态
const UptState=(vid:number)=>{
    if(confirm("您确定要修改当前状态吗?")){
    axios.get("https://localhost:7185/api/QY/UptStateQY",{params:{id:vid}}).then(res=>{
        if(res.data>0){
            alert("修改状态成功");
           Shows();
        }else{
            alert("修改状态失败");
            return;
        }
    })
}
}

//修改状态
const Dels=(vid:number)=>{
    if(confirm("您确定要删除吗?")){
    axios.delete("https://localhost:7185/api/QY/DelQy",{params:{id:vid}}).then(res=>{
        if(res.data>0){
            alert("删除成功");
           Shows();
        }else{
            alert("删除失败");
            return;
        }
    })
}
}



//前往添加
const GetAdd=()=>{
    touer.push({path:'/QyAdd'});
}

//前往修改
const GetUpt=(vid:number)=>{
    if(confirm("确定要去修改权益吗")){
        touer.push({path:'/QyUpt',query:{id:vid}});
    }

}



</script>

<style scoped>

</style>